package com.etc.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.etc.entity.Person;
import com.etc.service.PersonService;
import com.etc.service.impl.PersonServiceImpl;

public class PersonAddServlet extends HttpServlet {

	/**
	 * The doPost method of the servlet. <br>
	 * 
	 * This method is called when a form has its tag value method equals to
	 * post.
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		// 完成注册的添加

		// 1. 获取请求参数
		
		  String account = request.getParameter("account");
		  String pwd = request.getParameter("pwd");
		  String name = request.getParameter("name");
		  double balance=0;
		  String  phone=request.getParameter("phone");
		  String address = request.getParameter("address");
		  int state=0;
		
		// 2. 把请求参数封装到entity中
		Person person = new Person();
		person.setAccount(account);
		person.setPwd(pwd);
		person.setName(name);
		person.setBalance(balance);
		person.setPhone(phone);
		person.setAddress(address);
		person.setState(state);
		// 3. 调用业务对象
		PersonService personService = new PersonServiceImpl();
		personService.add(person);

		// 4. 页面的跳转 相当于访问 http://localhost:8080/myweb/index.jsp
		response.sendRedirect("index.jsp");
	}

}